<script setup lang="ts">
import { ref } from "vue";
import ReCol from "@/components/ReCol";
import { formRules } from "../utils/rule";
import { FormProps } from "../utils/types";
import { usePublicHooks } from "../../hooks";
const props = withDefaults(defineProps<FormProps>(), {
  formInline: () => ({
    title: "新增",
    parentId: 0,
    nickname: "",
    username: "",
    password: null,
    mobile: "",
    email: "",
    gender: "",
    status: 1,
    roleId: 1,
    remark: ""
  })
});

const sexOptions = [
  {
    value: 0,
    label: "女"
  },
  {
    value: 1,
    label: "男"
  }
];
const ruleFormRef = ref();
const newFormInline = ref(props.formInline);
const { switchStyle } = usePublicHooks();
function getRef() {
  return ruleFormRef.value;
}

defineExpose({ getRef });
</script>

<template>
  <el-form ref="ruleFormRef" :model="newFormInline" :rules="formRules" label-width="82px">
    <el-row :gutter="30">

      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="用户账号" prop="username">
          <el-input v-model="newFormInline.username" clearable placeholder="请输入用户名称" />
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="用户昵称" prop="nickname">
          <el-input v-model="newFormInline.nickname" clearable placeholder="请输入用户昵称" />
        </el-form-item>
      </re-col>
      <re-col v-if="newFormInline.title === '新增'" :value="12" :xs="24" :sm="24">
        <el-form-item label="用户密码" prop="password">
          <el-input v-model="newFormInline.password" clearable placeholder="请输入用户密码" />
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="手机号码" prop="mobile">
          <el-input v-model="newFormInline.mobile" clearable placeholder="请输入手机号" />
        </el-form-item>
      </re-col>

      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="邮箱" prop="email">
          <el-input v-model="newFormInline.email" clearable placeholder="请输入邮箱" />
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="性别">
          <el-select v-model="newFormInline.gender" placeholder="请选择用户性别" class="w-full" clearable>
            <el-option v-for="(item, index) in sexOptions" :key="index" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
      </re-col>

      <re-col v-if="newFormInline.title === '新增'" :value="12" :xs="24" :sm="24">
        <el-form-item label="状态">
          <el-switch v-model="newFormInline.status" inline-prompt :active-value="1" :inactive-value="0" active-text="启用"
            inactive-text="停用" :style="switchStyle" />
        </el-form-item>
      </re-col>

      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="角色">
          <el-select v-model="newFormInline.roleId" placeholder="请选择" class="w-full" clearable>
            <el-option v-for="(item, index) in roleOptions" :key="index" :value="item.id" :label="item.value">
              {{ item.value }}
            </el-option>
          </el-select>
        </el-form-item>
      </re-col>

      <re-col>
        <el-form-item label="备注">
          <el-input v-model="newFormInline.remark" placeholder="请输入备注信息" rows="6" type="textarea" />
        </el-form-item>
      </re-col>
    </el-row>
  </el-form>
</template>
